﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame2
{
    class Circle
    {
        private float radius;
        private Vector2 center;

        //
        private float closestX, closestY, distanceX, distanceY, distanceSquared;

        public float Radius
        {
            get { return radius;}
            set { radius = value;}
        }
        
        public float X
        {
            get { return center.X; }
            set { center.X = value; }
        }
        public float Y
        {
            get { return center.Y; }
            set { center.Y = value; }
        }
        public Vector2 Center
        {
            get { return center; }
            set { center = value; }
        }

        public Circle(float a_radius, Vector2 a_center)
        {
            radius = a_radius;
            center = a_center;
        }

        public Circle(float a_radius, float a_centerX, float a_centerY)
        {
            radius = a_radius;
            center = new Vector2(a_centerX, a_centerY);
        }

        public void Move(float theXPositionAdjustment, float theYPositionAdjustment)
        {
            center.X += theXPositionAdjustment;
            center.Y += theYPositionAdjustment;
        }

        public bool Intersects(RotatedRectangle a_rect)
        {
            // Find the closest point to the circle within the rectangle
            closestX = MathHelper.Clamp(center.X, a_rect.CollisionRectangle.Left, a_rect.CollisionRectangle.Right);
            closestX = MathHelper.Clamp(center.X, a_rect.CollisionRectangle.Top, a_rect.CollisionRectangle.Bottom);

            //// Calculate the distance between the circle's center and this closest point
            distanceX = center.X - closestX;
            distanceY = center.Y - closestY;

            //// If the distance is less than the circle's radius, an intersection occurs
            distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
            return distanceSquared < (radius * radius);
        }
    }
}

